﻿#region 程序集 VanillaPsycastsExpanded, Version=1.1.0.0, Culture=neutral, PublicKeyToken=null
// C:\code\MyMod\MOD\bin\this!!!!!!!1\1.4\Assemblies\VanillaPsycastsExpanded.dll
// Decompiled with ICSharpCode.Decompiler 7.1.0.6543
#endregion

using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using RimWorld;
using RimWorld.BaseGen;
using RimWorld.QuestGen;
using RimWorld.SketchGen;
using UnityEngine;
using Verse;
using Verse.Noise;
using RimWorld.BaseGen;
using ResolveParams = RimWorld.BaseGen.ResolveParams;
using RimWorld.Planet;

namespace WhoXiuXian
{
    public class SymbolResolver_RI_TalisAncientCryptosleepCasket : SymbolResolver
    {
        public override void Resolve(ResolveParams rp)
        {
            int groupID = rp.ancientCryptosleepCasketGroupID ?? Find.UniqueIDsManager.GetNextAncientCryptosleepCasketGroupID();
            PodContentsType value = rp.podContentsType ?? Gen.RandomEnumValue<PodContentsType>(disallowFirstValue: true);
            Rot4 rot = rp.thingRot ?? Rot4.North;
            Building_AncientCryptosleepCasket building_AncientCryptosleepCasket = (Building_AncientCryptosleepCasket)ThingMaker.MakeThing(ThingDefOf.AncientCryptosleepCasket);
            building_AncientCryptosleepCasket.groupID = groupID;
            ThingSetMakerParams parms = default(ThingSetMakerParams);
            parms.podContentsType = value;
            List<Thing> list = ThingSetMakerDefOf.MapGen_AncientPodContents.root.Generate(parms);
            for (int i = 0; i < list.Count; i++)
            {
                if (!building_AncientCryptosleepCasket.TryAcceptThing(list[i], allowSpecialEffects: false))
                {
                    Pawn pawn = list[i] as Pawn;
                    if (pawn != null)
                    {
                        Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Discard);
                    }
                    else
                    {
                        list[i].Destroy();
                    }
                }
            }

            IntVec3 randomCell = rp.rect.RandomCell;
            GenSpawn.Spawn(building_AncientCryptosleepCasket, randomCell, BaseGen.globalSettings.map, rot);
            if (rp.ancientCryptosleepCasketOpenSignalTag != null)
            {
                SignalAction_OpenCasket obj = (SignalAction_OpenCasket)ThingMaker.MakeThing(ThingDefOf.SignalAction_OpenCasket);
                obj.signalTag = rp.ancientCryptosleepCasketOpenSignalTag;
                obj.caskets.Add(building_AncientCryptosleepCasket);
                GenSpawn.Spawn(obj, randomCell, BaseGen.globalSettings.map);
            }
        }
    }
}